﻿//-------------------------------------------------------------------
//版权所有：版权所有(C) 2010， YIBO(China) Studio 
//系统名称：验证控件
//文件名称：InputStringClientValidator.cs
//模块名称：验证控件
//模块编号：
//作　　者：LHC
//完成日期：2010/8/29 14:34:00
//功能说明：
//-----------------------------------------------------------------
//修改记录：
//修改人：  
//修改时间：
//修改内容：
//-------------------------------------------------------------------

#region 程序集 YIBO.Validator, v1.0.100829

using System.Globalization;
using System.ComponentModel;

#endregion

namespace MvcMall.Framework.FormValidator
{
    /// <summary>
    /// 空值验证控件
    /// </summary>
    public class InputStringClientValidator : ClientValidator
    {
        /// <summary>
        /// 最少长度
        /// </summary>
        private int lowerBound;
        /// <summary>
        /// 正则表达式
        /// </summary>
        private string regex;
        /// <summary>
        /// 最大长度
        /// </summary>
        private int upperBound;

        /// <summary>
        /// 创建脚本容器
        /// </summary>
        /// <returns>返回容器对象</returns>
        internal override ValidateRenderControl GenerateAppendScript()
        {
            return new ValidateRenderControl();
        }

        /// <summary>
        /// 初始化验证控件脚本
        /// </summary>
        /// <returns>返回验证空值控件对象</returns>
        internal override ValidateRenderControl GenerateInitScript()
        {

            ValidateRenderControl control = new ValidateRenderControl();
            control.Text = string.Format(CultureInfo.InvariantCulture, "initValid(new InputValidator('{0}', {1}, {2}, {3}, {4}, '{5}', '{6}'", new object[] { base.Owner.TargetClientId, this.LowerBound, this.UpperBound, base.Owner.Nullable ? "true" : "false", string.IsNullOrEmpty(this.Regex) ? "null" : ("'" + this.Regex + "'"), base.Owner.Nullable ? base.Owner.FocusMessage : (base.Owner.RequiredAlt + base.Owner.FocusMessage), base.Owner.Nullable ? this.ErrorMessage : (base.Owner.RequiredMessage + this.ErrorMessage) });
            if (base.Owner.Nullable)
            {
                control.Text = control.Text + string.Format(CultureInfo.InvariantCulture, ", '{0}'", new object[] { base.Owner.NullMessage });
            }
            control.Text = control.Text + "));";
            return control;
        }

        /// <summary>
        /// 最少长度
        /// </summary>
        [Category("Validator")]
        [Description("最少长度")]
        public int LowerBound
        {
            get
            {
                return this.lowerBound;
            }
            set
            {
                this.lowerBound = value;
            }
        }

        /// <summary>
        /// 正则匹配表达式
        /// </summary>
        [Category("Validator")]
        [Description("正则匹配表达式")]
        public string Regex
        {
            get
            {
                return this.regex;
            }
            set
            {
                this.regex = value;
            }
        }

        /// <summary>
        /// 最大长度
        /// </summary>
        [Category("Validator")]
        [Description("最大长度")]
        public int UpperBound
        {
            get
            {
                return this.upperBound;
            }
            set
            {
                this.upperBound = value;
            }
        }
    }
}

